<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@page import="com.cap.bts.framework.usermgnt.constant.EmployeeStatus"%>    
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>会员卡配送</title>
<%@include file="../include/include.jsp"%>
<link rel="stylesheet" type="text/css" href="${csspath }/public.css"/>
<link rel="stylesheet" type="text/css" href="${csspath }/datepicker.css"/>
<link rel="stylesheet" type="text/css" href="${csspath }/style_l.css"/>
<script type="text/javascript" src="${jspath }/jquery-1.4.4.js"></script>
<script type="text/javascript" src="${jspath }/jquery.ui.min.js"></script>
<script type="text/javascript" src="${jspath }/ui.datepicker_zh-CN.js"></script>
<script type="text/javascript" src="${jspath }/jquery.blockUI.js"></script>
<script type="text/javascript" src="${jspath }/public.js"></script>
<script type="text/javascript" src="${jspath }/jquery.selectAll.js"></script>
<script type="text/javascript" src="${jspath}/jquery/jquery.ui.draggable.js"></script>
<script type="text/javascript" src="${jspath}/jquery/jquery.alerts.js"></script>
<script type="text/javascript" src="${jspath}/load_layer.js"></script>
<link rel="stylesheet" type="text/css" href="${csspath}/jquery.alerts.css" />

<link rel="stylesheet" type="text/css"
	href="${webcontext}/css/validationEngine.jquery.css" />
<script src="${jspath}/jquery/validate/jquery.validationEngine.js"
	type="text/javascript"></script>
<script src="${jspath}/jquery/validate/jquery.validationEngine-zh.js"
	type="text/javascript"></script>
	<script type="text/javascript"
	src="${webcontext}/javascript/jquery/jquery.ui.draggable.js"></script>
<link rel="stylesheet" type="text/css"
	href="${bootstrapPath}/css/bootstrap.css" />
<script type="text/javascript" src="${bootstrapPath}/js/bootstrap.js"></script>
<style type="text/css">
.formError .formErrorContent {
    -moz-border-radius: 6px 6px 6px 6px;
    -moz-box-shadow: 0 0 6px #000000;
    background: none repeat scroll 0 0 #EE0101;
    border: 2px solid #DDDDDD;
    color: #FFFFFF;
    font-family: tahoma;
    font-size: 11px;
    padding: 4px 10px;
    width: 100px;
}
</style>
<script type="text/javascript">
var myHeight = 0;
$(function(){
	
	$("#search_form").validationEngine(
			{
             promptPosition:"topLeft",
             success:false,
             validationEventTriggers:"blur",
             scroll : false,
			 failure:function(){} 
	});
	var today = new Date();   
	var day = today.getDate();   
	var month = today.getMonth() + 1;   
	var year = today.getFullYear();    
	var date = year + "-" + month + "-" + day;
	var startDate = $("#startDate").val();	
	if(startDate == "" || startDate == undefined || startDate == null){
		/* document.getElementById("startDate").value = date; */
	}
	var endDate = $("#endDate").val();	
	if(endDate == "" || endDate == undefined || endDate == null){
		/* document.getElementById("endDate").value = date; */
	}
	
});


function search() {
	search_form.action="${webcontext}/crmdp/dealer/logistic/toQueryLogisitcReceivePage";
	document.getElementById("search_form").submit();
}

 function receive(id,cardDefId,shipAmount){	
	var receiveAmount=document.getElementById("receiveAmount"+id).value;
	var reg=/^[0-9]+$/;
	var today = new Date();   
	var day = today.getDate();   
	var month = today.getMonth() + 1;   
	var year = today.getFullYear();    
	var date = ""+year + "-" + month + "-" + day;
	if(!reg.test(parseInt(receiveAmount))){
		jAlert('实发数量必须为正整数', '提示');
	}else{
		if(parseInt(shipAmount)<parseInt(receiveAmount)){
			jAlert('实收数量不得大于实发数量', '提示');
		}else{
			if(parseInt(receiveAmount)==0||receiveAmount==""||receiveAmount==undefined||receiveAmount==null){
				jConfirm("确认实收数量为0","确认提示",function(result){
		    		if(result == true){	
						$.ajax({
							type:'POST',
							url: '${webcontext}/crmdp/dealer/logistic/toReceiveLogisitcPage',
							data :  "dealerId=${param.dealerId}&id="+id+"&cardDefId="+cardDefId+"&receiveAmount="+receiveAmount,
							dataType : 'json',
							success : function(result) {
								if(result){
									$("#receiveAmount"+id).parent("td").parent("tr").find("td").eq(9).html("已接收");
									$("#receiveAmount"+id).parent("td").parent("tr").find("td").eq(8).html(date);
									$("#receiveAmount"+id).parent("td").parent("tr").find("td").eq(10).html("<s><i></i></s>");
									$("#receiveAmount"+id).parent("td").parent("tr").find("td").eq(7).html(receiveAmount);
								}else{
									jAlert('更新失败，请重试', '提示'); 
								}
						    },
							error:function(result){
								jAlert('更新失败，请重试', '提示'); 
							}
						}); 
		    		}
		    	});
			}else{
				$.ajax({
				type:'POST',
				url: '${webcontext}/crmdp/dealer/logistic/toReceiveLogisitcPage',
				data : "dealerId=${param.dealerId}&id="+id+"&cardDefId="+cardDefId+"&receiveAmount="+receiveAmount,
				dataType : 'json',
				success : function(result) {
					if(result){
						$("#receiveAmount"+id).parent("td").parent("tr").find("td").eq(9).html("已接收");
						$("#receiveAmount"+id).parent("td").parent("tr").find("td").eq(8).html(date);
						$("#receiveAmount"+id).parent("td").parent("tr").find("td").eq(10).html("<s><i></i></s>");
						$("#receiveAmount"+id).parent("td").parent("tr").find("td").eq(7).html(receiveAmount);
					}else{
						jAlert('更新失败，请重试', '提示'); 
					}
			    },
				error:function(result){
					jAlert('更新失败，请重试', '提示'); 
				}
			}); 
			}
		} 
	}
} 

</script> 
</head>
<body>
	<div id="content">
	<div class="spliter h_5"></div>
	<div class="page_info"></div>
	<div class="spliter h_5"></div>
		<div id="row" >
			<form:form class="form-horizontal" id="search_form" method="post"
				modelAttribute="dto">
				<input type="hidden" name="dealerId" value="${param.dealerId}">
				<div class="row">
					<div class="form-group">
						<label class="col-sm-4 control-label" for="startDate">发货日期</label>
						<div class="col-sm-3">
							<input name="transactionStartDate" class="form-control input-sm validate[length[0,100]] date" id="startDate" type="text"
								 value="${dto.transactionStartDate}" />
						</div>
						<label class="col-sm-2 control-label" for="endDate">结束日期</label>
						<div class="col-sm-3">
							<input  name="transactionEndDate" class="form-control input-sm validate[length[0,100]] date" id="endDate" type="text"  value="${dto.transactionEndDate}"/>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="form-group">
						<label class="col-sm-4 control-label" for="orderNum">订单编号</label>
						<div class="col-sm-3">
							<input name="orderNum" class="form-control input-sm" id="orderNum" type="text" value="${dto.orderNum}"/>
						</div>
						<label for="orderStatus" class="col-sm-2 control-label">订单状态</label>
						<div class="col-sm-3">
							<form:select path="orderStatus" id="orderStatus" cssClass="form-control input-sm">
								<form:option value="">全部</form:option>
								<form:option value="0">在途</form:option>
								<form:option value="1">已接收</form:option>
							</form:select>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="form-group">
						<label class="col-sm-4 control-label" for="expressCom">物流公司</label>
						<div class="col-sm-3">
							<input name="expressCom" class="form-control input-sm" id="expressCom" type="text" value="${dto.expressCom}"/>
						</div>
						<label class="col-sm-2 control-label" for="expressNum">物流单号</label>
						<div class="col-sm-3">
							<input  name="expressNum" class="form-control input-sm" id="expressNum" type="text" value="${dto.expressNum}"/>
						</div>
					</div>
				</div>
				<div style="text-align: center; margin-top: 10px;">
					<button type="button" class="btn btn-success" onclick="search()"><i class="glyphicon glyphicon-search" style="color:#FFFFFF"></i>&nbsp;查询</button>
					<button type="reset" class="btn btn-success"><i class="glyphicon glyphicon-trash" style="color:#FFFFFF"></i>&nbsp;重置</button>
				</div>
			<!-- /search_div -->
			<div class="spliter h_5"></div>
			<div class="page_info"></div>
			<div class="spliter h_10"></div>
			<!-- data_div -->
			<div id="dataTable" class="data_div">
			<table id="table" class="table">
				<thead>
					<tr>
						<th>订单编号</th>
						<th>商品名称</th>
						<th>实发数量</th>
						<th>发货日期</th>
						<th>预计到货</th>
						<th>物流公司</th>
						<th>物流单号</th>
						<th>实收数量</th>
						<th>收货日期</th>
						<th>状态</th>
						<th>收货</th>
					</tr>
				</thead>
				<tbody>
					<core:forEach items="${resultList}" var="logisticResultsDto">
						<tr>
							<td class="align_l">${logisticResultsDto.orderNo}</td>
							<td class="align_l">${logisticResultsDto.cardName}</td>
							<td class="text-right">${logisticResultsDto.shipAmount}</td>
							<td class="align_r">${logisticResultsDto.shipDate}</td>
							<td class="align_r">${logisticResultsDto.estimatedArriveDate}</td>
							<td class="align_r">${logisticResultsDto.expressCom}</td>
							<td class="text-right">${logisticResultsDto.expressNo}</td>
							<td class="align_m"><core:choose>
									<core:when test="${logisticResultsDto.status == '在途'}">
										<input class="align_m" type='text'
											id='receiveAmount${logisticResultsDto.id}'
											name='receiveAmount' style="width: 70%"
											value="${logisticResultsDto.receiveAmount}">
									</core:when>
									<core:when test="${logisticResultsDto.status == '已接收'}">
			                        ${logisticResultsDto.receiveAmount}
			                        </core:when>
								</core:choose></td>
							<td class="align_m">${logisticResultsDto.receiveDate}</td>
							<td class="align_m"><core:choose>
									<core:when test="${logisticResultsDto.status == '在途'}">
										${logisticResultsDto.status}
									</core:when>
									<core:when test="${logisticResultsDto.status == '已接收'}">
										${logisticResultsDto.status}
									</core:when>
								</core:choose></td>
							<td class="align_m">
	                        <core:choose>
	                        <core:when test="${logisticResultsDto.status == '在途'}">
	                        <a href="javascript:receive(${logisticResultsDto.id},${logisticResultsDto.cardDefId},${logisticResultsDto.shipAmount});">收货</a>
	                      	</core:when>
	                        <core:when test="${logisticResultsDto.status == '已接收'}">
	                        <s><i></i></s>
	                        </core:when>
	                        </core:choose>
	                        </td>
						</tr>
					</core:forEach>
				</tbody>
			</table>
			</div>
			<!-- /data_div -->
            <!-- page_div -->
			<div class="page_div">
			    <%@include file="../common/page.jsp"%>
			</div>
			<!-- /page_div -->
			</form:form>
		</div>
		<!-- /wrap -->
		</div>
	<!-- /content -->
	</body>
	</html>